<html>
<head><meta charset="utf-8"><title>hover in attribute macros · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html">hover in attribute macros</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246449114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246449114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246449114">(Jul 19 2021 at 12:40)</a>:</h4>
<p>Since when can we do hover and goto def in attribute macros? I don't remember fixing this <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span>  <a href="/user_uploads/4715/7dsnDTThI5zERZndkNOo-SLH/screenshot-2021-07-19-143853.png">screenshot-2021-07-19-143853.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/7dsnDTThI5zERZndkNOo-SLH/screenshot-2021-07-19-143853.png" title="screenshot-2021-07-19-143853.png"><img src="/user_uploads/4715/7dsnDTThI5zERZndkNOo-SLH/screenshot-2021-07-19-143853.png"></a></div>



<a name="246449123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246449123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246449123">(Jul 19 2021 at 12:40)</a>:</h4>
<p>very cool though <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="246449289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246449289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246449289">(Jul 19 2021 at 12:42)</a>:</h4>
<p>I fixed that two weeks ago or so I think</p>



<a name="246449306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246449306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246449306">(Jul 19 2021 at 12:42)</a>:</h4>
<p>Though its very much just heuristics</p>



<a name="246449688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246449688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246449688">(Jul 19 2021 at 12:46)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/pull/9420">https://github.com/rust-analyzer/rust-analyzer/pull/9420</a> and <a href="https://github.com/rust-analyzer/rust-analyzer/pull/9437">https://github.com/rust-analyzer/rust-analyzer/pull/9437</a>, I thought I only implemented that for attribute paths and not the token trees though <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="246449959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246449959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246449959">(Jul 19 2021 at 12:49)</a>:</h4>
<p>ah, nice :)</p>



<a name="246450141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246450141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246450141">(Jul 19 2021 at 12:50)</a>:</h4>
<p>It bothered me not seeing a hover for hover/goto def/syntax highlighting etc not working there so I just had the urge to fix it <span aria-label="big smile" class="emoji emoji-1f604" role="img" title="big smile">:big_smile:</span></p>



<a name="246450459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246450459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246450459">(Jul 19 2021 at 12:54)</a>:</h4>
<p>so how far are we from completing paths inside <code>salsa::invoke(&lt;|&gt;)</code> <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="246450462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246450462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246450462">(Jul 19 2021 at 12:54)</a>:</h4>
<p>Actually, no the the tokentree stuff in the attributes is different is it not? Thats macro token mappings right? That I didn't touch <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="246450680"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246450680" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246450680">(Jul 19 2021 at 12:56)</a>:</h4>
<p>yeah, I would have expected some changes to token mapping to be required here</p>



<a name="246450707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246450707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246450707">(Jul 19 2021 at 12:57)</a>:</h4>
<p>Ye then I can't take credit for this, I only made it work for the path of attributes again</p>



<a name="246450756"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246450756" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246450756">(Jul 19 2021 at 12:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="129457">Florian Diebold</span> <a href="#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/hover.20in.20attribute.20macros/near/246450459">said</a>:</p>
<blockquote>
<p>so how far are we from completing paths inside <code>salsa::invoke(&lt;|&gt;)</code> <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>
</blockquote>
<p>Once we get a proper way to understand paths in attribute token trees I suppose. We still have the completion problem with clippy lints that adds the full path even if qualified again resulting in<code>clippy::clippy::foo</code></p>



<a name="246450904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246450904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246450904">(Jul 19 2021 at 12:58)</a>:</h4>
<p>I think we're very far off from completing <code>salsa::invoke(&lt;|&gt;)</code>, but very close to completing <code>salsa::invoke(a&lt;|&gt;)</code></p>



<a name="246450957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246450957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246450957">(Jul 19 2021 at 12:59)</a>:</h4>
<p>well I mean, if you have a proc macro <code>foo!(something_used_as_a_path)</code> I think we can already complete the path. Certainly we can for macro_rules</p>



<a name="246450961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246450961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246450961">(Jul 19 2021 at 12:59)</a>:</h4>
<p>For the first one, salsa's macros themselves would need to be error-tolerant, and we'd still have no token to map into the expansion</p>



<a name="246451040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246451040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246451040">(Jul 19 2021 at 13:00)</a>:</h4>
<p>yeah that'd require error-tolerance or speculative expansion again</p>



<a name="246451105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246451105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246451105">(Jul 19 2021 at 13:00)</a>:</h4>
<p>For the second one, that should be a matter of just mapping the token into the output like we do for fn-like macros</p>



<a name="246451242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246451242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246451242">(Jul 19 2021 at 13:01)</a>:</h4>
<p>hmm, the completion context already tries to do that</p>



<a name="246451418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246451418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246451418">(Jul 19 2021 at 13:03)</a>:</h4>
<p>hmm, this code looks a bit questionable:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">original_token</span><span class="w"> </span><span class="o">=</span><span class="w"></span>
<span class="w">            </span><span class="n">original_file</span><span class="p">.</span><span class="n">syntax</span><span class="p">().</span><span class="n">token_at_offset</span><span class="p">(</span><span class="n">position</span><span class="p">.</span><span class="n">offset</span><span class="p">).</span><span class="n">left_biased</span><span class="p">()</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">token</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sema</span><span class="p">.</span><span class="n">descend_into_macros</span><span class="p">(</span><span class="n">original_token</span><span class="p">.</span><span class="n">clone</span><span class="p">());</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">scope</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sema</span><span class="p">.</span><span class="n">scope_at_offset</span><span class="p">(</span><span class="o">&amp;</span><span class="n">token</span><span class="p">,</span><span class="w"> </span><span class="n">position</span><span class="p">.</span><span class="n">offset</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>it calls <code>scope_at_offset</code> with the original offset, but the token from the macro expansion. is that correct?</p>



<a name="246454476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246454476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246454476">(Jul 19 2021 at 13:28)</a>:</h4>
<p>Good question, do we even need an offset there at all?</p>



<a name="246454665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246454665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246454665">(Jul 19 2021 at 13:29)</a>:</h4>
<p>Apparently we do</p>



<a name="246455584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246455584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246455584">(Jul 19 2021 at 13:37)</a>:</h4>
<p>Actually this seems fine? We seem to iterate the scopes at that position which have the original ranges again once out of the macro if i see this right</p>



<a name="246456156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246456156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246456156">(Jul 19 2021 at 13:42)</a>:</h4>
<p>yeah, the real reason this doesn't work is probably because the code at the bottom of <code>CompletionContext::new</code> only handles <code>ast::MacroCall</code></p>



<a name="246456189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/hover%20in%20attribute%20macros/near/246456189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/hover.20in.20attribute.20macros.html#246456189">(Jul 19 2021 at 13:42)</a>:</h4>
<p>and we have to implement speculative expansion for attribute macros for this to work</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>